const sql = require('../../config/config');

// 获取导航栏数据
function getNav() {
    return sql('select * from nav');
}

// 获取首页展示商品数据
function getGoods1() {
    return sql('select * from goods_item where category = 1 and isShow = 1');
}

// 获取首页展示商品数据
function getGoods2() {
    return sql('select * from goods_item where category = 2 and isShow = 1');
}

// 获取首页轮播图数据
function getBanner() {
    return sql('select * from banner where isShow = 1');
}

// 获取首页商品配件展示轮播图数据
function getCarousel() {
    return sql('select * from carousel where isShow = 1');
}

// 获取登录用户的昵称
function getNickname(arr) {
    return sql('select nickname from user where id = ?',arr);
}

// 获取分类页展示的商品信息
function getProducts() {
    return sql('select * from product');
}

// 获取详情页展示的商品信息
function getProduct(arr) {
    return sql('select * from product where id = ?',arr);
}

// 获取推荐商品的数据
function getRecommend(arr) {
    return sql('select id,title,price,mainimage from product where id = ? or id = ? or id = ? or id = ? or id = ?',arr);
}

// 获取该用户购物车的商品信息
function getCartData(arr) {
    return sql('select id,mainimage,price,title,quantity,checked,carid,stock from product join cart on product.id = cart.proid where cart.userid = ?', arr);
}

// 获取订单信息
function getOrderData(arr) {
    return sql("select * from orders where orderid = ?",arr);
}

module.exports = {
    getNav,
    getGoods1,
    getGoods2,
    getBanner,
    getCarousel,
    getNickname,
    getProducts,
    getProduct,
    getRecommend,
    getCartData,
    getOrderData
};
